var t = getApp(),
  a = t.requirejs("core"),
  e = t.requirejs("jquery");
Page({
  data: {
    cates: [],
    cateid: 0,
    page: 1,
    loading: false,
    loaded: false,
    list: [],
    keyword: '',
    disopt: [],
    range: 0,
  },
  onLoad: function (z) {
    var b = this;
    console.log(t.globalData.mid);
    var mypos = wx.getStorageSync("cityInfo");
    b.setData({ myloc: wx.getStorageSync("cityInfo")});
    ///没有地址
    if (!b.data.myloc)  {
      console.log('服务器端获取用户位置数据'),
      wx.showToast({
        title: 'hello',
      }) 
    }
    
    if (!mypos) {
      //1、获取当前位置坐标
      wx.getLocation({
        type: 'wgs84',
        success: function (res) {
          //2、根据坐标获取当前位置名称，显示在顶部:腾讯地图逆地址解析
          //console.log(res);
          wx.setStorageSync("cityInfo", res);
        },
        fail: function () {
          wx.getSetting({
            success: function (t) {
              0 == t.authSetting["scope.userLocation"] && wx.showModal({
                title: "提示",
                content: "您点击了拒绝授权,无法正常使用功能，点击确定重新获取授权。",
                showCancel: !1,
                success: function (t) {
                  t.confirm && (wx.openSetting({
                    success: function (t) {
                      t.authSetting["scope.userLocation"];
                      that.dwreLoad();
                    }
                  }));
                }
              });
            }
          });
        }
      })
    } 
    b.getList();
  },
  
  getList: function () {
    var p = this;//console.log(t.data.mypos);
    var mid = t.globalData.mid;
    var cityInfo = wx.getStorageSync("cityInfo");
    a.get("changce/merchStore/get_detail", { id: mid, cityInfo: cityInfo }, function (a) {
      p.setData({
        merchInfo:a.merch,
        list: a.merch.storeList
      })
    });
  },
 choose_address:function(){
  var p = this;
   wx.authorize({ scope: "scope.userLocation" }),
   wx.chooseLocation({
        success(res){
          wx.setStorageSync("cityInfo",res);
          p.onLoad();
        }
   })
 },
  goaddress : function(o){
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        wx.openLocation({
          latitude: parseFloat( o.currentTarget.dataset.lat ),
          longitude: parseFloat( o.currentTarget.dataset.lng ),
          name: o.currentTarget.dataset.name,
          address: o.currentTarget.dataset.address
        })
      }
    });
  },
  joinus: function(e){
    if (e.currentTarget.dataset.url){
      wx.reLaunch({
        url: e.currentTarget.dataset.url
      })
    }
  },
  clickBtn:function(o){
    var storeInfo = this.data.list;
    if (storeInfo[o.currentTarget.dataset.id]){
      wx.setStorageSync("storeInfo", storeInfo[o.currentTarget.dataset.id]);
      wx.showModal({
        title: "提示",
        content: "选择成功",
        showCancel: !1,
        success: function (t) {
          wx.reLaunch({
            url: "/pages/changce/merch/detail"
          })
        }
      });
    
    }
    
  }
})